<ul class="list links">
<?php
if ($links):
	foreach ($links->result() as $link):
?>
	<li>
		<a
		href="<?php echo prep_url($link->url); ?>"
		rel="<?php echo $link->rel; ?>"
		target="_blank"><?php echo $link->title ? htmlentities($link->title) : $link->url; ?></a>
		
		<?php if ($this->userland->logged_in() && $this->userland->user_role() == 5): ?>
			<a href="/bricabox/<?php echo $bricabox->id; ?>/remove_link/<?php echo $link->id; ?>/<?php echo $bricabox->id; ?>/<?php echo md5('w00p'.$link->id.$bricabox->id.$this->userland->current_user()->id); ?>" onclick="return confirm('Are you sure?');" title="Remove link">
				<img style="vertical-align: middle;" src="/assets/images/icons/cross.png" alt="Remove link" />
			</a>
		<?php endif; ?>
	</li>
<?php
	endforeach;
else:
?>
	<li><strong>No one has added any links yet.</strong></li>
<?php endif; ?>
</ul>

<?php if ($this->userland->logged_in()): ?>

	<?php if (!preg_match('/entries/', $this->uri->uri_string()) && $this->userland->user_role()): ?>
		<p style="margin: 8px 0;">
			<a class="links-add"
			href="#"
			onclick="$('#add_links_<?php echo $block_instance['data']->id; ?>').toggle();return false;">
			Add a link</a></p>
		<div id="add_links_<?php echo $block_instance['data']->id; ?>" style="display: none;">
			<h4>Add a new link to this list:</h4>
			<form action="/bricabox/<?= $bricabox->id; ?>/add_link" method="post">
				<input type="hidden" name="content_id" value="<?php echo $content_id; ?>" />
				<input type="hidden" name="instance_id" value="<?php echo $block_instance['data']->id; ?>" />
				<fieldset>
			
					<div><label for="link_url_<?php echo $block_instance['data']->id; ?>">URL (required):</label><br />
					<input type="text" name="link_url" id="link_url_<?php echo $block_instance['data']->id; ?>" /></div>
			
					<div><label for="link_title_<?php echo $block_instance['data']->id; ?>">Title:</label><br />
					<input type="text" name="link_title"
					id="link_title_<?php echo $block_instance['data']->id; ?>" /></div>
			
					<div><label for="link_rel_<?php echo $block_instance['data']->id; ?>">
						<code style="font: 12px Monaco, monospaced;">rel</code> attribute:</label><br />
					<input type="text" name="link_rel"
					id="link_rel_<?php echo $block_instance['data']->id; ?>" /></div>
			
					<div class="controls">
						<input type="submit" value="Add this link" />
						or <a href="#" onclick="$('#add_links_<?php echo $block_instance['data']->id; ?>').toggle(); return false;">cancel</a>
					</div>
				</fieldset>
			</form>
		</div>
	<?php endif; ?>

<?php else: ?>
<a href="/sign_up_or_log_in">Sign up or log in to add links</a>
<?php endif; ?>